package com.store.app.dialog;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import com.store.app.R;

/**
 * author lushan
 * on 2017/3/23 0023 16:34
 */

public class AlertTipsDialog extends Dialog implements android.view.View.OnClickListener{

    private Context mContext;
    private Activity mActivity;
    /**
     * 确定按钮
     **/
    private Button confirmBtn;

    /**
     * 取消按钮
     **/
    private Button cancelBtn;

    private AlertDialogListener mAlertDialogListener;

    private TextView quit_dialog_content_tv;
    private TextView quit_dialog_title_tv;
    private EditText et_content;

    public AlertTipsDialog(Context context, AlertDialogListener l) {
        super(context);
        this.mContext = context;
    }

    public AlertTipsDialog(Activity context, int themeResId, AlertDialogListener l) {
        super(context, themeResId);
        mContext = context;
        mActivity = context;
        this.mAlertDialogListener = l;
    }

    public String getContent(){
        return et_content.getText().toString().trim();
    }
    public void setDialogContent(int text) {
        quit_dialog_content_tv.setText(text);
    }

    public void setDialogContent(String text) {
        quit_dialog_content_tv.setText(text);
    }

    public void setDialogTitle(int text) {
        quit_dialog_title_tv.setText(text);
    }

    public void setDialogTitle(String text) {
        quit_dialog_title_tv.setText(text);
    }

    public void showCancleBtn(boolean isshow) {
        if (isshow) {
            quit_dialog_title_tv.setVisibility(View.VISIBLE);
        } else {
            quit_dialog_title_tv.setVisibility(View.GONE);
        }
    }
    public void showEdit(){
        if(et_content!=null){
            et_content.setVisibility(View.VISIBLE);
        }
    }
    public void setsetFalseCancelable(){
        setCancelable(false);
    }
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // 指定布局
        this.setContentView(R.layout.dialog_tips);
        DisplayMetrics metric = new DisplayMetrics();
        mActivity.getWindowManager().getDefaultDisplay().getMetrics(metric);
        WindowManager.LayoutParams p = getWindow().getAttributes();
        p.width = (int) (metric.widthPixels - 100);
        Window window = getWindow();
        window.setAttributes(p);
        window.setGravity(Gravity.CENTER);
        setCancelable(true);
        this.setCanceledOnTouchOutside(true);

        confirmBtn = (Button) findViewById(R.id.confirm_btn);
        cancelBtn = (Button)findViewById(R.id.cancel_btn);
        quit_dialog_title_tv = (TextView) findViewById(R.id.quit_dialog_title_tv);
        quit_dialog_content_tv = (TextView) findViewById(R.id.quit_dialog_content_tv);
        et_content = (EditText) findViewById(R.id.et_content);

        // 为按钮绑定点击事件监听器
        confirmBtn.setOnClickListener(this);
        cancelBtn.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.confirm_btn:

                mAlertDialogListener.onConfirmClick();
                break;
            case R.id.cancel_btn:
                mAlertDialogListener.onCancelClick();
                break;
        }
    }

    public interface AlertDialogListener {
        void onConfirmClick();

        void onCancelClick();
    }

}
